package com.sitech.portal.panels.action;

import com.opensymphony.xwork2.ActionSupport;
import com.sitech.ibnms.util.JSONUtil;
import com.sitech.portal.panels.service.PanelSettingService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by liujhc on 1/3.
 */
public class PanelSettingAction extends ActionSupport {
    @Autowired
    private PanelSettingService panelSettingService;
    private String panelId;
    private String valueType;
    private Object result;

    public String querySettings() {
        if ("list".equals(valueType) || "array".equals(valueType)) {
            result = panelSettingService.queryPanelSettingsAsList(panelId);
        } else {
            result = panelSettingService.queryPanelSettingsAsMap(panelId);
        }
        return SUCCESS;
    }

    public String saveSettings() {
        if (result != null) {
            panelSettingService.savePanelSettings(panelId, result);
        }
        return SUCCESS;
    }

    public void setPanelId(String panelId) {
        this.panelId = panelId;
    }

    public void setValueType(String valueType) {
        this.valueType = valueType;
    }

    public Object getResult() {
        return result;
    }

    public void setSettingsJson(String settingJson) {
        this.result = JSONUtil.fromJSON(settingJson);
    }
}
